package com.book.controller;

import com.book.config.SystemConfig;
import com.book.param.UserAdd;
import com.book.param.UserFind;
import com.book.param.UserLogin;
import com.book.param.UserLoginCode;
import com.book.service.TbUserService;
import com.book.vo.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * (TbUser)表控制层
 *
 * @author makejava
 * @since 2024-11-07 19:53:31
 */
@RestController
@RequestMapping("api/tbUser")
@Tag(name = "用户模块")
public class TbUserController{
    /**
     * 服务对象
     */
    @Resource
    private TbUserService service;
    @Operation(summary = "用户注册")
    @PostMapping("register")
    public R register(@RequestBody UserAdd add){
        return service.register(add);
    }
    @Operation(summary = "用户登录")
    @PostMapping("login")
    public R login(@RequestBody UserLogin login){
        return service.login(login);
    }
    @Operation(summary = "修改密码")
    @PostMapping("updatepass")
    public R updatePass(@RequestBody Map<String,String> map, HttpServletRequest request){
        return service.updatePass(map.get("password"),request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @Operation(summary = "所有用户")
    @GetMapping("all")
    public R all(){
        return service.queryAll();
    }

    @Operation(summary = "发送登录验证码")
    @GetMapping("sendlcode")
    public R sendLcode(String phone){
        return service.sendLcode(phone);
    }

    @Operation(summary = "校验登录验证码")
    @PostMapping("logincode")
    public R loginCode(@RequestBody UserLoginCode code){
        return service.loginCode(code);
    }

    @Operation(summary = "密码找回验证码")
    @GetMapping("sendfcode")
    public R sendFcode(String phone){
        return service.sendFcode(phone);
    }

    @Operation(summary = "密码找回")
    @PostMapping("findpass")
    public R findPass(@RequestBody UserFind find){
        return service.findPass(find);
    }
    @Operation(summary = "退出登录")
    @GetMapping("logout")
    public R logout(HttpServletRequest request){
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        return service.logout(token);
    }

}

